
***
*want to assign each czone to a state
*most czones don't cross state boundaries -> no issue
*if the czone does cross a state boundary, want to assign based on 2000 population

use "$dir/data/interim/cw_cty_czone_puma2000_afact.dta", clear

tostring(puma2000), gen(puma2000_s)

gen state  = substr(puma2000_s, 1, 2)


replace state = substr(puma2000_s, 1, 1) if puma2000<1000000

drop puma2000_s

collapse (sum) pop2k, by(czone state)

by czone, sort: egen max_pop = max(pop2k)

gen state_assigned = (pop2k==max_pop)

destring state, replace

replace state_assigned = state if state_assigned ==1

collapse (max) state_assigned, by(czone)

save "$dir/data/interim/pop_weighted_state_czone.dta", replace
